/* 
 * File:   Scene.h
 * Author: brady
 *
 * Created on February 2, 2011, 7:04 PM
 */


#include <vector>
#include <stack>
#include "Shape.h"
#include "Camera.h"
#include "Light.h"
#include <PNGImage.h>
#include "BoundingVolumeNode.h"
#include <pthread.h>
#include <float.h>


using namespace std;

#ifndef SCENE_H
#define	SCENE_H


struct Pixel{int x; int y;};


class Scene {
public:
    Scene();
    virtual ~Scene();
    void AddShape(Shape* s);
    void AddCamera(Camera* camera);
    void AddLight(Light* light);
    bool CaptureImageMT(string path, Camera* camera, int resX, int resY, int threadCount);
    void BuildBVH();
    int RDepth;
    bool useBVH;
    BoundingVolumeNode* BVHRoot;
    Vector3D BGColor;
    double Tmin;
    double Tmax;
    int SamplesPerPixel;
    bool SoftShading;
    vector<Light*> lights;
    vector<Shape*> shapes;
    vector<Camera*> cameras;
    stack<Pixel*> Pixels;
    bool preSampling;
    double differenceThreshold;
private:
    double ComputeEpsilon();
};

struct ThreadInfo{stack<Pixel*> *pixels; Scene* scene; Camera* camera; float* imageData; int threadCount;};
static pthread_mutex_t pixelsMutex;
static pthread_mutex_t shapeMutex;
static pthread_mutex_t coutMutex;
static void* RenderPixels(void* threadData);
static void RandomizeArray(int* randMap, int samples);

#endif	/* SCENE_H */

